﻿namespace Common.Architecture.Common
{
    /// <summary>
    /// 扩展类
    /// 里面定义的是扩展方法
    /// 用this作为类型控制的关键字
    /// 
    /// </summary>
    public static class Extensions
    {
        /// <summary>
        /// 扩展字符串转数字
        /// </summary>
        /// <param name="value"></param>
        /// <returns></returns>
        public static int ToInt32(this string? value)
        {
            if(value==null)
            {
                return 0;
            }
            else
            {
                return Convert.ToInt32(value);
            }
        }
        /// <summary>
        /// 扩展根据身份证计算出生年月日
        /// </summary>
        /// <param name="carId">身份证号</param>
        /// <returns></returns>
        public static string GetBirthByCarId(this string carId)
        {
            //130434 20061023 4842
            string result = carId.Substring(6,8);
            return result;
        }
        /// <summary>
        /// 扩展年月日 YYYY年mm月dd日
        /// </summary>
        /// <param name="Time"></param>
        /// <returns></returns>
        public static string GetYearMonthDay(this DateTime Time)
        {
            return Time.ToString("yyyy-MM-dd");
        }

    }
}
